package com.crungoo;

import com.crungoo.proxy.IndexServiceProxyLog;
import com.crungoo.proxy.IndexServiceProxyLogPower;
import com.crungoo.reflect.Proxy;
import com.crungoo.services.IndexService;
import com.crungoo.services.MyService;
import com.crungoo.services.impl.MyServiceImpl;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @author : fujc-dev@qq.com
 * @created : 2022/7/5 14:01
 */

public class App {

	public static void main(String[] args) {
		System.out.println("动态代理：");
		//System.out.println(new Date());
		//AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
		//System.out.println(context.getBean(AppConfig.class));

		//DataSource dataSource = null;
		//TransactionFactory transactionFactory = new JdbcTransactionFactory();
		//Environment environment = new Environment("development", transactionFactory, dataSource);
		//Configuration configuration = new Configuration(environment);
		//configuration.addMapper(AppConfig.class);
		//SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
		//SqlSession sqlSession = sqlSessionFactory.openSession();
		//AppConfig mappper = sqlSession.getMapper(AppConfig.class);

		//能够得到一个实现了UserDao的对象
		//UserDao userDao= (UserDao) LubanFactory.getMapper(UserDao.class);
		// 完成数据库的查询功能
		//userDao.query();
		//System.out.println("============================");
		//IndexService service = new IndexServiceProxyLog();
		//service.query();
		//System.out.println("============================");
		//IndexService service1 = new IndexServiceProxyLogPower();
		//service1.query();

		try {
			MyService service = new MyServiceImpl();
			MyService proxy = (MyService) Proxy.newInstacen(service);
			proxy.getAll("1", "1", "1");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
}
